package com.mytest.offer;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

@Slf4j
public class SolutionJZ25 {

    public static void main(String[] args) {
        SolutionJZ25 solutionJZ6 = new SolutionJZ25();
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);

        listNode.next = listNode1;
        listNode1.next = listNode2;

        solutionJZ6.merge(listNode,null);
    }

    public ListNode merge(ListNode list1, ListNode list2) {

        ListNode currentNode = new ListNode(-1);
        ListNode head = currentNode;
        while(list1 != null || list2!= null){
            if (list1 == null && list2 != null){
                currentNode.next = list2;
                break;
            } else if (list1 != null && list2 == null){
                currentNode.next = list1;
                break;
            }else if (list1.val > list2.val){
                currentNode.next = list2;
                list2 = list2.next;
            } else {
                currentNode.next = list1;
                list1 = list1.next;
            }
            currentNode = currentNode.next;
        }
        return head.next;
    }
}
